package com.qianye.redisUtil;

import com.qianye.exception.NullException.NullException;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Author: hjz
 * @DataTime: 2024/9/18 22:53
 **/
public interface RedisUtils {
    /**
     * 设置key-value
     * <p>
     * timeout为空时，表示永久有效
     * <p>
     * 此方法含有过期时间
     *
     * @param key
     * @param value
     * @param timeout
     * @param unit
     * @return Boolean
     */
    Boolean setForRedis(String key, Object value, Long timeout, TimeUnit unit);

    /**
     * 设置key-value
     * <p>
     * 永久
     *
     * @param key
     * @param value
     * @return Boolean
     */
    Boolean setForRedis(String key, Object value);

    /**
     * 获取key对应的value
     *
     * @param key
     * @return Object
     */
    Object getForRedis(String key);

    /**
     * 批量获取key对应的value
     *
     * @param keys
     * @return List<Object>
     */
    List<Object> multiGet(Collection<String> keys) throws NullException;

    /**
     * 删除key对应的value
     *
     * @param key
     * @return Boolean
     */
    Boolean deleteForRedis(String key);

    /**
     * 批量删除key对应的value
     *
     * @param keys
     * @return Long
     */
    Long multiDelete(Collection<String> keys);

    /**
     * 设置key的过期时间
     *
     * @param key
     * @param timeout
     * @param unit
     * @return Boolean
     */
    Boolean expireForRedis(String key, Long timeout, TimeUnit unit);
}
